import { RootThunkAction } from '..'
import axios from 'axios'
export type Channel = {
  id: number
  name: string
}

export type TypeChannelAction =
  | {
      type: 'channel/getChannelList'
      payload: Channel[] //[{id:1,name:'jack'},{}]
    }
  | { type: 'channel/changeActive'; payload: number }
export const channelAction = (): RootThunkAction => {
  return async (dispatch: any) => {
    const res = await axios.get('http://geek.itheima.net/v1_0/channels')
    // console.log(res, 8877)

    dispatch({
      type: 'channel/getChannelList',
      payload: res.data.data.channels,
    })
  }
}

export const channelLightAction = (id: number): RootThunkAction => {
  return async (dispatch: any) => {
    dispatch({
      type: 'channel/changeActive',
      payload: id,
    })
  }
}
